#include <STC89C5xRC.H>
#include "Delay.h"
#include "LCD1602.h"
#include "Timer0.h"

unsigned int Sec,Min,Hour,Ms;
void main()
{		
	Timer0Init();	
	LCD_Init();
	LCD_ShowString(1,1,"Clock:");
	LCD_ShowString(2,1,":");
	LCD_ShowString(2,3,":");
	LCD_ShowString(2,6,":");
	LCD_ShowString(2,9,":");

	while(1)
	{
		LCD_ShowNum(2,7,Sec,2);
		LCD_ShowNum(2,4,Min,2);
		LCD_ShowNum(2,1,Hour,2);
		LCD_ShowNum(2,10,Ms,2);
	}
}

void Timer0_Routine() interrupt 1//定时器0对应的interrupt 1，为其对应的中断函数
{	
	static unsigned int T0Count; //静态局部变量，保证退出函数时不丢失
	TL0 = 0x00;		//设置定时初值
	TH0 = 0xDC;		//设置定时初值
	T0Count++;
	if(T0Count==1)
	{	
		T0Count=0;
		Ms++;
		if(Ms>=100)
		{	
			Ms=0;
			Sec++;
			if(Sec>=60)
			{
				Sec=0;
				Min++;
				if(Min>=60)
				{
					Min=0;
					Hour++;
					if(Hour>=24)
					{
						Hour=0;
					}
				}
			}
		}
	}
}